import { useState } from "react";
import { Form } from "antd";
import { useRequest } from "ahooks";

import prompt from "vendor/utils/prompt";
import { getLoginUserInfo, updatePersonInfo } from '../api'

export const usePersonInfo = () => {
  const [form] = Form.useForm();
  const [saving, setSaving] = useState(false);
  const { data:loginUserInfo, loading } = useRequest(() => getLoginUserInfo().then(resp => resp.data));
  
  const submit = () => {
    setSaving(true)
    form.validateFields().then((values) => {
      updatePersonInfo(values).then(() => {
        prompt.success("修改成功")
        setSaving(false)
      }).catch(() => setSaving(false))
    }).catch(() => setSaving(false))
  }

  return { form, saving, submit, loading, loginUserInfo }
}
